test(fastapi): ServeCommand tests via Cleo CommandTester#123
Merged
Conversation
Drive the serve command end-to-end via Cleo's CommandTester — no manual option stubbing. 18 cases cover defaults, CLI --host/--port overrides, config-driven host/port, app-found vs not-found paths, and uvicorn kwargs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e in ServeCommand Add a new standalone `value()` helper to the environment module that casts an already-resolved value to the appropriate Python type (int, bool, None, str) without performing any os.getenv lookup. Fix `ServeCommand.resolve_option()` which was calling `env(value)` on an already-resolved host/port string — `env()` treats its first argument as an env-var name, so it silently dropped the resolved value. Replace the call with `cast_value()` (the new `value()` function) so host/port are cast correctly without a spurious os.getenv lookup. Also update test_serve_command.py to remove the now-unnecessary `env` identity-patch workaround that masked the bug. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
f9f533c5serve command code intact (resolve_option/resolve_urlapproach)tests/fastapi/test_serve_command.pywith 18 test cases driven entirely through Cleo'sCommandTester— no ad-hoc option stubbinguvicorn.run,Config.get, andenvare patched so tests run without a live app or networkTest coverage
TestServeCommandDefaultswskwargTestCliOptions--host/--portin output and forwarded to uvicornTestConfigOptionsapp_urlbehaviourTestAppFoundfactory=True, app string kwargTestAppNotFoundfactorykwarg,reload=FalseTest plan
uv run pytest tests/fastapi/test_serve_command.py -v→ 18 passed🤖 Generated with Claude Code